package com.kitty.game.talk.facade;

import com.kitty.game.role.model.Role;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.npc.message.ReqTaskTalk;
import com.kitty.game.talk.service.TalkService;
import com.kitty.listener.EventType;
import com.kitty.listener.annotation.EventHandler;
import com.kitty.listener.event.LoginEvent;
import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.SessionUtils;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;

@Controller
public class TalkController {


    /**点击任务对话*/
    @RequestMapping
    public void reqTaskTalk(IoSession session, ReqTaskTalk reqTaskTalk) {
        Role role = SessionUtils.getRoleBySession(session);
        /**新建角色后角色还没登录，role可能为null*/
        // TODO 暂时还直接返回，后面再看怎么弄
        if (role == null) {return ;}
        SpringUtils.getBean(TalkService.class).requestTaskTalk(role, reqTaskTalk.getTalkId(), reqTaskTalk.getType());
    }

    @EventHandler(EventType.LOGIN)
    public void handleLoginEvent(LoginEvent loginEvent) {
        SpringUtils.getBean(TalkService.class).handleLogin(loginEvent.getRole());
    }
}
